package com.atom.module.picker

import android.content.Context
import android.net.Uri

/**
 * ### 选择结果
 *
 * @author javakam
 * @date 2020/5/14  10:32
 */
class FileSelectResult(
    var mUri: Uri
) {

    private var mFilePath: String? = null
    fun getFilePath(context: Context): String? {
        if (mFilePath == null) {
            mFilePath = FileUri.getPathByUri(context, mUri)
        }
        return mFilePath
    }

    private var mFileSize: Long? = null
    fun getFileSize(context: Context): Long? {
        if (mFileSize == null) {
            mFileSize = FileSizeUtils.getFileSize(context, mUri)
        }
        return mFileSize
    }

    private var mMimeType: String? = null
    fun getMimeType(context: Context): String {
        if (mMimeType == null) {
            mMimeType = FileMimeType.getMimeType(getFilePath(context))
        }
        return mMimeType!!
    }

    private var mFileType: FileType? = null
    fun getFileType(context: Context): FileType {
        if (mFileType == null) {
            mFileType = FileType.fromUri(context, mUri)
        }
        return mFileType!!
    }

    fun string(context: Context): String {
        return """
            FileResult:
            uri : ${mUri}
            path : ${getFilePath(context)}
            size : ${getFileSize(context)}
            type : ${getFileType(context)}
            Mime : ${getMimeType(context)}
        """.trimIndent()
    }

}